package cn.edu.jnu.supershopper;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;

public class BackgroundUtil {
    Context context;

    public BackgroundUtil(Context context){
        this.context = context;
    }

    //图片伸缩变换
    public static Bitmap zoomImg(Bitmap bitmap, int new_w,int new_h){
        //获取图片当前宽高
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        // 计算缩放比例
        float scaleW = ((float) new_w)/width;
        float scaleH = ((float) new_h)/height;
        //取得想要缩放的matrix参数
        Matrix matrix = new Matrix();
        matrix.postScale(scaleW,scaleH);
        //获得新的图片
        Bitmap new_bit = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true);
        return new_bit;
    }


}
